﻿Imports ASAP.InterfazNegocio

Public Class usrInfoEjercicio

    Private ejer As TiposDatosSTE.Ejercicio
    Private pathTemporal As String

    Public Sub inicializa(ByVal ejer As TiposDatosSTE.Ejercicio)
        Me.ejer = ejer
        Me.tbNivel.Text = ejer.Nivel
        Me.tbTipoEjer.Text = ejer.TipoEjercicio
        Me.tbVolumen.Text = CStr(ejer.Volumen)
        Me.tbTema.Text = ejer.Tema
        pathTemporal = My.Application.Info.DirectoryPath & "\tmp"

        'Historico
        Dim PorcentageAcierto As Integer
        Dim NumVecesCorrecto As Integer
        Dim NumVecesErroneo As Integer
        For Each res As TiposDatosSTE.Resultado In ejer.Resultados
            If res.Correcto Then
                NumVecesCorrecto = NumVecesCorrecto + 1
            Else
                NumVecesErroneo = NumVecesErroneo + 1
            End If
        Next
        If NumVecesCorrecto + NumVecesErroneo = 0 Then
            PorcentageAcierto = 0
        Else
            PorcentageAcierto = CInt(Math.Round(NumVecesCorrecto / (NumVecesCorrecto + NumVecesErroneo), 0))
        End If
        Me.tbRespCorrectas.Text = CStr(NumVecesCorrecto)
        Me.tbRespIncorrectas.Text = CStr(NumVecesErroneo)
        Me.tbPorcenAcierto.Text = CStr(PorcentageAcierto)


    End Sub

    Private Sub AbrirAudio()
        Dim PathAudio = pathTemporal & "\audio.mp3"

        If Not IO.Directory.Exists(pathTemporal) Then
            IO.Directory.CreateDirectory(pathTemporal)
        End If

        My.Computer.FileSystem.WriteAllBytes(PathAudio, Agente.DameAudio(ejer), False)
        System.Diagnostics.Process.Start(PathAudio)
    End Sub

    Private Sub AbrirImagenesLibro()

        Dim PathImagenes = pathTemporal & "\libro.tif"

        If Not IO.Directory.Exists(pathTemporal) Then
            IO.Directory.CreateDirectory(pathTemporal)
        End If

        My.Computer.FileSystem.WriteAllBytes(PathImagenes, Agente.DameImagenesLibro(ejer), False)
        System.Diagnostics.Process.Start(PathImagenes)
    End Sub


#Region "Eventos"

    Private Sub tbVerLeccion_PreviewMouseLeftButtonUp(ByVal sender As Object, ByVal e As System.Windows.Input.MouseButtonEventArgs) Handles tbVerLeccion.PreviewMouseLeftButtonUp
        Try
            AbrirImagenesLibro()
        Catch ex As Exception
            MsgBox(ex.ToString)
        End Try
    End Sub

    Private Sub tbAudioLeccion_PreviewMouseLeftButtonUp(ByVal sender As Object, ByVal e As System.Windows.Input.MouseButtonEventArgs) Handles tbAudioLeccion.PreviewMouseLeftButtonUp
        Try
            AbrirAudio()
        Catch ex As Exception
            MsgBox(ex.ToString)
        End Try
    End Sub

    Private Sub tbVerHistorico_PreviewMouseLeftButtonUp(ByVal sender As Object, ByVal e As System.Windows.Input.MouseButtonEventArgs) Handles tbVerHistorico.PreviewMouseLeftButtonUp
        Dim frmHistorico As New Historico
        frmHistorico.inicializa(ejer)
        frmHistorico.ShowDialog()
        frmHistorico.Close()
    End Sub

#End Region


End Class
